//
//  ViewController.m
//  test12
//
//  Created by 贺嘉炜 on 2016/12/8.
//  Copyright © 2016年 贺嘉炜. All rights reserved.
//

#import "ViewController.h"
#import "Filter2ViewController.h"
#import "UIView+AutoLayout.h"
#import "Masonry.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet UIView *greenView;
@property (weak, nonatomic) IBOutlet UIView *blueView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self demo33];
}

- (void)demo33{
    
    Filter2ViewController *filterVc = [[Filter2ViewController alloc]init];
    [self addChildViewController:filterVc];
    [self.view addSubview:filterVc.view];
    [filterVc.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        filterVc.cons = make.height.mas_equalTo(50);
        NSLog(@"");
    }];
    
}



- (void)demo32{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.width.equalTo(self.greenView.mas_width);
    }];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisVertical];
    [self.redView autoSetDimension:ALDimensionWidth toSize:self.greenView.bounds.size.width];

    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.top.mas_equalTo(100);
    }];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:100];
}

- (void)demo31{
    UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    priceLabel.backgroundColor = [UIColor yellowColor];
    priceLabel.adjustsFontSizeToFitWidth = YES;
    [self.greenView addSubview:priceLabel];
    
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.mas_equalTo(0);
        make.left.equalTo(self.redView.mas_right);
        make.width.mas_equalTo(50);
    }];
    
//    [priceLabel autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0) excludingEdge:ALEdgeLeading];
//    [priceLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.redView withOffset:0];
//    [priceLabel autoSetDimension:ALDimensionWidth toSize:50];
}

- (void)demo30{
    UIButton *checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
    checkButton.frame = CGRectMake(185, 12, 18, 18);
    checkButton.backgroundColor = [UIColor yellowColor];
    [self.greenView addSubview:checkButton];
    [checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(6);
        make.bottom.mas_equalTo(-6);
        make.right.mas_equalTo(-20);
    }];
    [checkButton autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(6, 0, 6, 20) excludingEdge:ALEdgeLeft];
}

- (void)demo29{
//    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.bottom.bottom.mas_equalTo(0);
//        make.left.equalTo();
//        make.width.mas_equalTo(50);
//    }];
    
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0) excludingEdge:ALEdgeLeading];
    [self.redView autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.blueView withOffset:0];
    [self.redView autoSetDimension:ALDimensionWidth toSize:50];
}


- (void)demo28{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.greenView).offset(-120);
        make.centerY.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(140, 40));
    }];
    [self.redView autoAlignAxis:ALAxisVertical toSameAxisOfView:self.greenView withOffset:-120];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.redView autoSetDimensionsToSize:CGSizeMake(140, 40)];
}

- (void)demo27{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.greenView).offset(120);
        make.centerY.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(140, 40));
        
    }];
    [self.redView autoAlignAxis:ALAxisVertical toSameAxisOfView:self.greenView withOffset:120];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.redView autoSetDimensionsToSize:CGSizeMake(140, 40)];
}

- (void)demo26{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(120, 40));
    }];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisVertical];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.redView autoSetDimensionsToSize:CGSizeMake(120, 40)];
}

- (void)demo25{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop];
    [self.redView autoSetDimension:ALDimensionHeight toSize:50];
//    self.filterVc.allheightConstraint =  
}

- (void)demo24{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(84);
    }];
    
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisVertical];
    [self.redView autoSetDimension:ALDimensionHeight toSize:84];
    [self.redView autoSetDimension:ALDimensionWidth toSize:84];
}

- (void)demo23{
    [self.redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.blueView.mas_right).offset(10);
        make.top.equalTo(self.blueView.mas_top);
        make.size.mas_equalTo(CGSizeMake(60, 20));
    }];
    [self.redView autoPinEdge:ALEdgeLeft toEdge:ALEdgeTrailing ofView:self.blueView withOffset:10];
    [self.redView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.blueView withOffset:0];

    [self.redView autoSetDimension:ALDimensionWidth toSize:60];
    [self.redView autoSetDimension:ALDimensionHeight toSize:20];
}

- (void)demo22{
    UILabel *processWordLabel = [[UILabel alloc]init];
    [self.view addSubview:processWordLabel];
    processWordLabel.text = @"I am a label and I am awesome";
    processWordLabel.backgroundColor = [UIColor yellowColor];
    
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(43, 43));
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(10);
    }];
}


- (void)demo21{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(20);
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:0];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:0];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
    [self.redView autoSetDimension:ALDimensionHeight toSize:20];
}


- (void)demo20{
//    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 10, 0, 10));
//    }];
//    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
    
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 95, 0, 10));
    }];
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 95, 0, 10)];
}

- (void)demo19{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(89, 22));
        make.left.mas_equalTo(100);
        make.centerY.mas_equalTo(0);
    }];
    
    [self.redView autoSetDimension:ALDimensionWidth toSize:89];
    [self.redView autoSetDimension:ALDimensionHeight toSize:22];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:100];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
}

- (void)demo18{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, 22));
        make.left.mas_equalTo(10);
        make.centerY.mas_equalTo(0);
    }];
    
    [self.redView autoSetDimension:ALDimensionWidth toSize:100];
    [self.redView autoSetDimension:ALDimensionHeight toSize:22];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:10];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
}

- (void)demo17{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero];
}

- (void)demo16{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(44);
    }];
    
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop];
    [self.redView autoSetDimension:ALDimensionHeight toSize:44];
}

- (void)demo15{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(27, 15));
        make.centerY.equalTo(self.greenView);
        make.left.mas_equalTo(1000);
    }];
    [self.redView autoSetDimension:ALDimensionWidth toSize:27];
    [self.redView autoSetDimension:ALDimensionHeight toSize:15];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    //layoutRecommendHCenter =
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:1000];
    //layoutRecommendLeft =
}

- (void)demo14{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(29, 29));
        make.centerY.equalTo(self.greenView);
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:10];
    [self.redView autoSetDimension:ALDimensionWidth toSize:29];
//    self.redViewViewWidthContraint = 
    [self.redView autoSetDimension:ALDimensionHeight toSize:29];
//    self.redViewViewHeightContraint = 
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
//    iconCenterXContraint =  
}

- (void)demo13{
    CGFloat SUB_TITLE_WIDTH = [UIScreen mainScreen].bounds.size.width - 49 - 34;
    
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(SUB_TITLE_WIDTH, 20));
        make.left.mas_equalTo(49);
        make.centerY.mas_equalTo(self.greenView).offset(8);
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:49];
    [self.redView autoSetDimension:ALDimensionWidth toSize:SUB_TITLE_WIDTH];
    //self.subTitleContraint =
    
    [self.redView autoSetDimension:ALDimensionHeight toSize:20];
    [self.redView autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.greenView withOffset:8];
//    layoutSubTitleHeight = 
}

- (void)demo12{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(49);
        make.right.mas_equalTo(-34);
        make.height.mas_equalTo(30);
        make.centerY.equalTo(self.greenView);
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:49];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:34];
    [self.redView autoSetDimension:ALDimensionHeight toSize:30];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
//    layoutTitleHeight =
}

- (void)demo11{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(24, 24));
        make.right.mas_equalTo(-10);
        make.centerY.equalTo(self.greenView);
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:10];
    [self.redView autoSetDimension:ALDimensionWidth toSize:24];
    [self.redView autoSetDimension:ALDimensionHeight toSize:24];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    //chooseBtnCenterXContraint =
}


- (void)demo10{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    
    [self.redView autoSetDimension:ALDimensionHeight toSize:50.0f];
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeBottom];
}

- (void)demo9{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(20);
    }];
    
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop];
    [self.redView autoSetDimension:ALDimensionHeight toSize:20];
}

- (void)demo8{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [self.redView autoSetDimension:ALDimensionWidth toSize:20];
    [self.redView autoSetDimension:ALDimensionHeight toSize:20];
}

- (void)demo7{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [self.redView autoSetDimension:ALDimensionWidth toSize:20];
    [self.redView autoSetDimension:ALDimensionHeight toSize:20];
}

- (void)demo6{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(1);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, -1, 0) excludingEdge:ALEdgeTop];
    [self.redView autoSetDimension:ALDimensionHeight toSize:1];
}

- (void)demo5{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(20);
    }];
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop];
    [self.redView autoSetDimension:ALDimensionHeight toSize:20];
}

- (void)demo4{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    [self.redView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero ];
}

- (void)demo3{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-10);
        make.size.mas_equalTo(CGSizeMake(20, 12));
        make.centerY.equalTo(self.view);
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:10];
    [self.redView autoSetDimensionsToSize:CGSizeMake(20, 12)];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
}

- (void)demo2{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(44);
        make.trailing.mas_equalTo(-40);
        make.height.mas_equalTo(22);
        make.centerY.equalTo(self.view);
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:44];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:40];
    [self.redView autoSetDimension:ALDimensionHeight toSize:22];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
}

- (void)demo1{
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(24, 24));
        make.centerY.equalTo(self.view);
    }];
    
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:10];
    [self.redView autoSetDimensionsToSize:CGSizeMake(24, 24)];
    [self.redView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
}

- (void)demo0{
    CGFloat top = 5;
    CGFloat left = 2;
    CGFloat bottom = 50;
    CGFloat right = 20;

    UIEdgeInsets padding = UIEdgeInsetsMake(top, left, bottom, right);
    [self.redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.redView.superview).with.insets(padding);
    }];

    [self.redView  autoAlignAxisToSuperviewAxis:ALAxisVertical];
    [self.redView  autoSetDimension:ALDimensionWidth toSize:CGRectGetWidth(self.view.bounds)];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:top];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:left];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:bottom];
    [self.redView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:right];
}


@end
